@extends('backend.template.bootstrap')
@section('content')
<div class="m-b-md">
	<h3 class="m-b-none">分类管理</h3>
</div>
<div class="row">
	<div class="col-lg-12">
		<ul class="breadcrumb">
			<li><a href="{{ url('backend') }}"><i class="fa fa-home"></i> 首页</a></li>
			<li><a href="{{ url('backend/categories') }}">分类管理</a></li>
			<li class="active">创建分类</li>
		</ul>
	</div>
</div>
@if (Session::has('msg'))
<div class="alert alert-dismissable alert-danger">
	<button type="button" class="close" data-dismiss="alert">×</button>
	<strong>消息提示：</strong> {{ Session::get('msg') }}
</div>
@elseif ($errors->any())
<div class="alert alert-danger" role="alert">
	<button type="button" class="close" data-dismiss="alert">×</button>
	<strong>消息提示：</strong> {{ $errors->first() }}
</div>
@endif
<section class="panel panel-default">
	<header class="panel-heading font-bold">
		@if (!$category->exists) 新建管理 @else
		编辑分类
		@endif
	</header>
	<div class="panel-body">
		@if (!$category->exists)
			{!! Form::open(array('route' => array('categories.store'), 'files' => true)) !!}
		@else
			{!! Form::model($category, array('method' => 'PATCH', 'route' => array('categories.update', $category->id), 'files' => true)) !!}
		@endif
			<div class="form-group">
				{!! Form::label('name', '分类名称', array('class' => 'control-label')) !!}
				{!! Form::text('name', $category->name, array('class' => 'form-control')) !!}
			</div>
			<div class="form-group">
				{!! Form::label('seq', '分类排序', array('class' => 'control-label')) !!}
				{!! Form::text('seq', $category->seq, array('class' => 'form-control', 'placeholder' => '正整数')) !!}
			</div>
			@if(!empty(Input::get('parentId')) || !empty($category->parent_id))
			<div class="form-group">
				{!! Form::label('parent_id', '上级分类', array('class' => 'control-label')) !!}
				@if(!empty(Input::get('parentId')))
				<p class="form-control-static">{{ App\Models\Category::find(Input::get('parentId'))->name }}</p>
				{!! Form::hidden('parent_id', Input::get('parentId')) !!}
				@endif
				@if(!empty($category->parent_id))
				<p class="form-control-static">{{ App\Models\Category::find($category->parent_id)->name }}</p>
				{!! Form::hidden('parent_id', $category->parent_id) !!}
				@endif
	  		</div>
	  		@endif
			<div class="form-group">
				{!! Form::label('description', '分类介绍', array('class' => 'control-label')) !!}
				{!! Form::textarea('description', $category->description, array('class' => 'form-control', 'rows' => '3')) !!}
	  		</div>
	  		<div class="form-group">
  				<button type="submit" class="btn btn-primary">
  					立即保存
  				</button>
				<a href="{{ url('backend/categories') }}" class="btn btn-default">返回</a>
	  		</div>
		{!! Form::close() !!}
	</div>
</section>
@stop